<div class="bjui-pageContent">
<form action="/admin/order/createOrderDistributionSubmit" id="create_order_distribution" data-toggle="ajaxform" data-alertmsg="true">
    <input type="hidden" name="order_pre_id" value="{{$orderPreId}}">
    <div class="bjui-row">

        <label class="row-label" style="text-align: left">收货人</label>
        <div class="row-input required">
            <input name="consignee"  value="@if(isset($orderDistributionPreRow['consignee'])) {{$orderDistributionPreRow['consignee']}} @endif" data-rule="required" type="text">
        </div>

        <label class="row-label" style="text-align: left">电话</label>
        <div class="row-input required">
            <input name="phone"  value="@if(isset($orderDistributionPreRow['phone'])) {{$orderDistributionPreRow['phone']}} @endif" data-rule="required" type="text">
        </div>

        <label class="row-label" style="text-align: left">区域</label>
        <div class="row-input required">

            <select name='province_id' id="sel_province">
                <option value="0">请选择省份</option>
                @foreach($provinceList as $val)
                <option value="{{$val['provinceID']}}" @if(isset($orderDistributionPreRow['province_id']) && $orderDistributionPreRow['province_id'] == $val['provinceID']) selected="" @endif>{{$val['province']}}</option>
                @endforeach
            </select>
            <select name='city_id' id="sel_city">
                <option value="0">请选择城市</option>
                @foreach($cityList as $val)
                <option value="{{$val['cityID']}}"  @if(isset($orderDistributionPreRow['city_id']) && $orderDistributionPreRow['city_id'] == $val['cityID']) selected="" @endif>{{$val['city']}}</option>
                @endforeach
            </select>
            <select name='area_id' id='sel_area'>
                <option value="0">请选择区域</option>
                @foreach($areaList as $val)
                <option value="{{$val['areaID']}}"  @if(isset($orderDistributionPreRow['area_id']) && $orderDistributionPreRow['area_id'] == $val['areaID']) selected="" @endif>{{$val['area']}}</option>
                @endforeach
            </select>

        </div>

        <label class="row-label" style="text-align: left">详细地址</label>
        <div class="row-input required">
            <input name="address"  value="@if(isset($orderDistributionPreRow['address'])) {{$orderDistributionPreRow['address']}} @endif" data-rule="required" type="text">
        </div>

    </div>
</form>
</div>

<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
        <li><button type="button" class="btn-default" data-icon="save" onclick="createOrderDistributionSubmit();">保存</button></li>
    </ul>
</div>

<script type="text/javascript">
    function createOrderDistributionSubmit(){
        BJUI.ajax('ajaxform', {
            url: '/admin/order/createOrderDistributionSubmit',
            form: $.CurrentDialog.find('#create_order_distribution'),
            validate: false,
            loadingmask: true,
            okCallback: function(json, options) {
                BJUI.dialog('close','add_distribution_dialog');
            }
        })
    }


    //省市区联动选择
    $(function(){
        $("#sel_province").change(function(){
            var provinceID=$(this).val();
            getCityList(provinceID);
        })

        $("#sel_city").change(function(){
            var cityID=$(this).val();
            getAreaList(cityID);
        })
    });
    function getCityList(provinceID){
        var city_id="";
        if(provinceID<1){
            var str='<option value="0">请选择城市</option>';
            $("#sel_city").html(str);
            str='<option value="">请选择区域</option>';
            $("#sel_area").html(str);
        }else{
            $.ajax({		//完整的ajax异步交互方法
                url:"/admin/order/getCityAreaList",
                type:'post',
                data:{		//参数
                    provinceID:provinceID,
                    type:'getCityList'
                },
                dataType:'json',
                async:false,
                success:function(data){
                    city_id =data[0].cityID;
                    var obj= data;
                    var str='<option value="0">请选择城市</option>';
                    $.each(obj,function(n,value) {
                        str +='<option value="'+value.cityID+'">'+value.city+'</option>';
                    });
                    $("#sel_city").html(str);
                }
            })
//            getAreaList(city_id);
        }


    }

    function getAreaList(cityID){
        if(cityID < 1){
            var str='<option value="">请选择区域</option>';
            $("#sel_area").html(str);
        }else{
            $.ajax({		//完整的ajax异步交互方法
                url:"/admin/order/getCityAreaList",
                type:'post',
                data:{		//参数
                    cityID:cityID,
                    type:'getAreaList'
                },
                dataType:'json',
                success:function(data){
                    var obj= data;
                    var str='<option value="">请选择区域</option>';
                    $.each(obj,function(n,value) {
                        str +='<option value="'+value.areaID+'">'+value.area+'</option>';
                    });
                    $("#sel_area").html(str);
                }
            })
        }
    }


</script>